import { Button, ButtonProps, Tag } from 'antd';
import React from 'react';
import { useFileDownload } from '..';
type FileDownloadProps<T extends React.ElementType> = {
  tag?: T;
  downloadName?: string
  url: string
  data?: { [key: string]: any } | Function
  newWindow?: boolean
  params?: { [key: string]: any } | Function
  method?: 'GET' | 'POST'
  apiPrefix?: string
  children: React.ReactNode;
} & React.ComponentProps<T>; // 使用 React.ComponentProps 获取传入组件的 props

const FileDownload = <T extends React.ElementType = typeof Button>({
  tag: Tag = Button as unknown as T,
  children,
  ...props
}: FileDownloadProps<T>) => {
  const { loading, onClick } = useFileDownload(props)
  return (<Tag loading={loading} onClick={onClick} {...props}>{children}</Tag>)
}

export default FileDownload